<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link href="<s:url value="/css/style.css"/>" rel="stylesheet"
			type="text/css" />
		<link href="<s:url value="/css/jquery.css"/>" rel="stylesheet"
			type="text/css" />
		<script type="text/javascript" src="<s:url value="/js/jquery.js"/>"></script>
		<script type="text/javascript" src="<s:url value="/js/jquery-ui.js"/>"></script>
		<script type="text/javascript" src="<s:url value="/js/common.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.bgiframe.min.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.ajaxQueue.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/thickbox-compressed.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.autocomplete.js"/>"></script>
		<link rel="stylesheet" type="text/css"
			href="<s:url value="/js/autocomplete/jquery.autocomplete.css"/>" />
		<script type="text/javascript" src="<s:url value="/js/jquery-ui.js"/>"></script>
		<link rel="stylesheet" type="text/css"
			href="<s:url value="/js/autocomplete/thickbox.css"/>" />
		<script type="text/javascript"
			src="<s:url value="/js/jquery.blockUI.js"/>"></script>
		<script type="text/javascript"
			src="<s:url value="/js/jquery.validate.js"/>"></script>
		<script type="text/javascript">
	   $(function(){
			 $('#startTime').datepicker({dateFormat:'yy-mm-dd'});
			 $('#endTime').datepicker({dateFormat:'yy-mm-dd'});
			 if($.trim($('#result').text())!=''){
			   	popupDiv('pop-div');
			 };
			 $('#editForm').validate();
			 $("#selCompany").autocomplete("<s:url value="/clt/Company/autoCompleteAjax.action"/>", {
		              width: 300,
		              minChars:2, //几个字
		              mastMatch:true,
		              selectFirst: false,
		              max:  20,
		           	  formatItem: function(row, i, max) {
		           	      //alert(row);
		           	      var d=eval("("+row+")");
		           	      //alert(d);
					      return  d.name;
			         },
				     formatMatch: function(row, i, max) {
				         var d=eval("("+row+")");
		 			     return  d.name;
				     },
				     formatResult: function(row) {
				        // alert(row);
				         var d=eval("("+row+")");
					     return d.name;
		     	      }
		     });
		     $("#selCompany").result(function(event, data, formatted) {
		           var d=eval("("+data+")");
				   $("#selCompanyId").val(d.id);
		     });
		});
	    function doSave() {
	        var selid=$("#selCompanyId").val();
	        if (!selid){
	            alert("please select one Company");
	            return;
	        }
            $('#editForm').submit();
	    };
	    function doArrange() {
	        var selid=$("#contractId").val();
	        if (!selid){
	            alert("please new contract first");
	            return;
	        }
	        location.href='<s:url value="/clt/CorpClass/edit?selContractId=%{id}"/>';
	    };
	    function doCommit() {
	       var selid=$("#selCompanyId").val();
	       if (!selid){
	            alert("please select one Company");
	            return;
	       }
		   if (!confirm("after commit you can't change everything,confirm!")){
		     return;
	       }
	       var form = $('#editForm');
	       form.attr('action',form.attr('action').replace('save','commit'));
           $('#editForm').submit();
	    };
		function goBack(){
			location.href='<s:url value="/clt/CorpContract/list"/>';
		};
		function  doPrice(){
			var p=0;
			if ($("#transportationFee").val()){
			   p+=parseInt($("#transportationFee").val());
			}
			if ($("#testingFee").val()){
			   p+=parseInt($("#testingFee").val());
			}
			if ($("#materialFee").val()){
			   p+=parseInt($("#materialFee").val());
			}
			if ($("#trainingFee").val()){
			   p+=parseInt($("#trainingFee").val());
			}
			$("#price").val(p)
		}
</script>
		<s:head />
		<title><s:text name="system.title" />
		</title>
	</head>
	<body>
		<s:include value="/common/up.jsp"></s:include>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td class="box">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td id="tag-over">
								<span id="tag-over">Contract</span>
							</td>
							<td class="tab3-line" width="90%">
								&nbsp;
							</td>
						</tr>
					</table>
					<s:form action="CorpContract/save" namespace="/clt" method="post"
						id="editForm" name="editForm">
						<s:set value="id" name="contractId" />
						<s:hidden id="contractId" name="id"></s:hidden>
						<table width="100%" border="0" cellpadding="3" cellspacing="1"
							class="margin">
							<tr>
								<td align="right" class="tablecolour5">
									Name:
								</td>
								<td class="tablecolour5" colspan="5">
									<s:if test="selCompanyId!=null">
										<input id="selCompany" size="50" type="text"
											readonly='readonly' disabled="disabled"
											value="<s:property value="company.name"/>" class="input2" />
										<s:hidden id="selCompanyId" name="selCompanyId" />
									</s:if>
									<s:else>
										<input id="selCompany" size="50" type="text" class="input2" />
										<s:hidden id="selCompanyId" name="selCompanyId" />
									</s:else>
								</td>
							</tr>
							<tr>
								<td align="right" class="tablecolour5">
									Contract No:
								</td>
								<td class="tablecolour5">
									<s:textfield id="contractNo" name="contractNo"
										cssClass="input2" />
								</td>
								<td align="right" class="tablecolour5">
									Price:
								</td>
								<td class="tablecolour5">
									<s:textfield name="price" id="price" cssClass="required number" />
									<s:select name="payMethod" headerKey=""
										cssClass="input2 required" headerValue="--select--"
										listKey="name()" list="@com.ef.constant.EPayMethod@values()" />
								</td>
							</tr>
							<tr>
								<td align="right" class="tablecolour5">
									Testing Fee:
								</td>
								<td class="tablecolour5">
									<s:textfield name="testingFee" onchange="doPrice()"
										id="testingFee" cssClass="number" />
								</td>
								<td align="right" class="tablecolour5">
									Transportation Fee:
								</td>
								<td class="tablecolour5">
									<s:textfield name="transportationFee" onchange="doPrice()"
										id="transportationFee" cssClass="number" />
								</td>
							</tr>
							<tr>
								<td align="right" class="tablecolour5">
									Material Fee:
								</td>
								<td class="tablecolour5">
									<s:textfield name="materialFee" onchange="doPrice()"
										id="materialFee" cssClass="number" />
								</td>
								<td align="right" class="tablecolour5">
									Training Fee:
								</td>
								<td class="tablecolour5">
									<s:textfield name="trainingFee" onchange="doPrice()"
										id="trainingFee" cssClass="number" />
								</td>
							</tr>
							<tr>
								<td align="right" class="tablecolour5">
									Begin:
								</td>
								<td class="tablecolour5">
									<s:date name="startTime" format="yyyy-MM-dd" var="startTimefmt" />
									<s:textfield name="startTime" id="startTime"
										cssClass="input2 required" value="%{startTimefmt}" />
								</td>
								<td align="right" class="tablecolour5">
									End:
								</td>
								<td class="tablecolour5">
									<s:date name="endTime" format="yyyy-MM-dd" var="endTimefmt" />
									<s:textfield name="endTime" id="endTime" value="%{endTimefmt}"
										cssClass="input2 required" />
								</td>
							</tr>
							<tr>
								<td align="right" class="tablecolour5">
									Course Type:
								</td>
								<td class="tablecolour5">
									<s:select name="course"
										list="@com.ef.constant.ECLTCourseCategory@values()"
										listKey="name()" />
								</td>
								<td align="right" class="tablecolour5">
									Comment:
								</td>
								<td class="tablecolour5">
									<s:textarea cols="40" rows="4" name="comments" />
								</td>
							</tr>
							<tr>
								<td align="center" colspan="4" height="50" class="tablecolour5">
									<input type="button" class="btn1" value="Save"
										onclick="doSave();" />
									<input type="button" class="btn1" value="Commit"
										onclick="doCommit();" />
									<input type="button" class="btn1" value="Arrange"
										onclick="doArrange();" />
									<input name="goback" type="button" class="btn1" value="Go Back"
										onclick="goBack()" />
								</td>
							</tr>
						</table>
						<table align="center" width="100%" border="0" cellpadding="0"
							cellspacing="1" class="box2">
							<tr>
								<td class="tablecolour1">
									ClassType
								</td>
								<td class="tablecolour1">
									Teacher
								</td>
								<td class="tablecolour1">
									Begin
								</td>
								<td class="tablecolour1">
									End
								</td>
								<td class="tablecolour1">
									Comment
								</td>
								<td class="tablecolour1">
									Function
								</td>
							</tr>
							<s:iterator value="corpClassList" status="status">
								<tr>
									<td class="tablecolour2">
										<s:property value="classtype.name" />
									</td>
									<td class="tablecolour2">
										<s:property value="teacher.name" />
									</td>
									<td class="tablecolour2">
										<s:date name="startTime" format="yyyy-MM-dd" />
									</td>
									<td class="tablecolour2">
										<s:date name="endTime" format="yyyy-MM-dd" />
									</td>
									<td class="tablecolour2">
										<s:property value="comments" />
									</td>
									<td class="tablecolour2">
										<a
											href='<s:url value="/clt/CorpClass/edit?id=%{id}&selContractId=%{contractId}"/>'>Edit</a>
									</td>
								</tr>
							</s:iterator>
						</table>
					</s:form>
				</td>
			</tr>
		</table>
		<s:include value="/common/down.jsp"></s:include>
		<div id='pop-div' style="width: 300px;" class="pop-box">
			<s:include value="/common/confirm.jsp"></s:include>
		</div>
	</body>
</html>